﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary.DAO;
using ClassLibrary.Entity;

namespace mprsc
{
    public partial class ListAction : Form
    {
        TblJobNoteDAO jobNoteDAO = new TblJobNoteDAO(Global.CONNECTION_STRING);

        public ListAction()
        {
            InitializeComponent();
        }

        private void ListAction_Load(object sender, EventArgs e)
        {
            this.CenterToScreen();
            LoadNotesType();
        }

        // load action list
        private void LoadNotesType()
        {
            grdJobList.DataSource = jobNoteDAO.GetJobNoteAll();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            // update xong- insert vo TblJobNotes
            TblJobNotes jobnote = new TblJobNotes();
            string idJobNote = grdJobList.CurrentRow.Cells["IDJobNote"].Value.ToString();
            // 0: not finish - 1: finish
            if (grdJobList.CurrentRow.Cells["ActionStatus"].Value.ToString() == "Not finish")
            {
                jobNoteDAO.Update(1, idJobNote);
            }
            else
            {
                jobNoteDAO.Update(0, idJobNote);
            }

            //jobnote.JobID = Global.ConvertToInt(t);
            string idJob = grdJobList.CurrentRow.Cells["JobID"].Value.ToString();
            jobnote.JobID = Global.ConvertToInt(idJob);

            jobnote.Notes = "Finish" + " .ACTION BY " + " Tên người login";
            jobnote.StatusJobNote = "Has been Actioned";
            jobnote.StatusJob = 1;
            jobnote.DateEntered = DateTime.Now;
            jobnote.NoteType = "Requires Action";
            jobnote.DateAction = DateTime.Now;

            jobNoteDAO.InsUp_JobNote(jobnote, 1);

            LoadNotesType();
        }

        private void btnDetail_Click(object sender, EventArgs e)
        {
            string idCus = grdJobList.CurrentRow.Cells["CustomerIndex"].Value.ToString();
            NewCustomer cus = new NewCustomer();
            cus.Sender(idCus);
            this.Hide();
            cus.Show();
        }
    }
}
